package com.zgscwjm.taobaphelper.xp;

import android.util.Log;

import org.apache.commons.lang.StringUtils;

import java.io.File;
import java.io.PrintStream;
import java.text.SimpleDateFormat;
import java.util.Date;

import jp.jun_nama.test.utf7ime.b.a;

import static com.zgscwjm.taobaphelper.b.a.a;

public class DSLogger {
    static String SYS_TAG = "SYS_DS";
    static String TAG = "DS";
    private static SimpleDateFormat df = null;
    static File logFile = new File("/data/local/tmp/ds_xposed.log");

    static {
        init();
    }

    public static void error(String str, Object... objArr) {
        String str2 = "DS[" + getDf().format(new Date()) + "] -> " + str;
        if (objArr == null || objArr.length <= 0) {
            Log.e(TAG, str2);
        } else {
            Log.e(TAG, String.format(str2, objArr));
        }
    }

    public static void error(Throwable th, String str, Object... objArr) {
        String str2 = "DS[" + getDf().format(new Date()) + "] -> " + str;
        if (objArr == null || objArr.length <= 0) {
            Log.e(TAG, str2, th);
        } else {
            Log.e(TAG, String.format(str2, objArr), th);
        }
    }

    protected static SimpleDateFormat getDf() {
        if (df != null) {
            return df;
        }
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        df = simpleDateFormat;
        return simpleDateFormat;
    }

    public static void info(String str, Object... objArr) {
        String str2 = "[" + getDf().format(new Date()) + "] -> " + str;
        if (objArr == null || objArr.length <= 0) {
            Log.i("DS", str2);
        } else {
            Log.i("DS", String.format(str2, objArr));
        }
    }

    public static void infos(String str, Object... objArr) {
        info(String.format(str, objArr), new Object[0]);
    }

    static void init() {
        String absolutePath = logFile.getAbsolutePath();
        if (!a.i(absolutePath)) {
            a.a(absolutePath, com.zgscwjm.taobaphelper.exutils.StringUtils.EMPTY);
            a.d(a.e("/data/data/", DSLogger.class.getPackage().getName()), absolutePath);
        }
    }

    public static void recFail(Throwable th, String str, Object... objArr) {
        th.printStackTrace();
        PrintStream printStream = System.err;
        String str2 = "DS[" + getDf().format(new Date()) + "] -> " + str;
        if (objArr == null || objArr.length <= 0) {
            Log.e(TAG, str2);
        } else {
            Log.e(TAG, String.format(str2, objArr));
        }
    }

    public static void warn(String str, Object... objArr) {
        String str2 = "[" + getDf().format(new Date()) + "] -> " + str;
        if (objArr == null || objArr.length <= 0) {
            Log.w("DS", str2);
        } else {
            Log.w("DS", String.format(str2, objArr));
        }
    }
}
